//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using Microsoft.Practices.ObjectBuilder;

namespace Microsoft.Practices.CompositeWeb.ObjectBuilder
{
    /// <summary>
    /// An implementation of <see cref="IBuilder{TStageEnum}"/> which uses <see cref="WCSFBuilderStage"/>
    /// as the stages of the build process. It is very similar to <see cref="Builder"/>, but has a custom
    /// locking strategy, which is finer grained than the previous locking strategy.
    /// </summary>
    public class WCSFBuilder : WCSFBuilderBase<WCSFBuilderStage>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="WCSFBuilder"/> class 
        /// </summary>
        public WCSFBuilder()
            : this(null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="WCSFBuilder"/> class using the provided
        /// configurator.
        /// </summary>
        /// <param name="configurator">The configurator that will configure the builder.</param>
        public WCSFBuilder(IBuilderConfigurator<WCSFBuilderStage> configurator)
        {
            Strategies.AddNew<TypeMappingStrategy>(WCSFBuilderStage.PreCreation);
            Strategies.AddNew<SingletonStrategy>(WCSFBuilderStage.PreCreation);
            Strategies.AddNew<ConstructorReflectionStrategy>(WCSFBuilderStage.PreCreation);
            Strategies.AddNew<PropertyReflectionStrategy>(WCSFBuilderStage.PreCreation);
            Strategies.AddNew<MethodReflectionStrategy>(WCSFBuilderStage.PreCreation);

            Strategies.AddNew<CreationStrategy>(WCSFBuilderStage.Creation);
            Strategies.AddNew<PropertySetterStrategy>(WCSFBuilderStage.Initialization);
            Strategies.AddNew<MethodExecutionStrategy>(WCSFBuilderStage.Initialization);

            Strategies.AddNew<BuilderAwareStrategy>(WCSFBuilderStage.PostInitialization);

            Policies.SetDefault<ICreationPolicy>(new DefaultCreationPolicy());

            if (configurator != null)
            {
                configurator.ApplyConfiguration(this);
            }
        }
    }

}
